<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class conectaMysqli {
    
    /**
     * Conexao com o banco de dados
     * @var mysqli
     */
    protected static $con;

    public static function get_mysqli(){
        if (!isset (self::$con)){
            self::$con = new mysqli("localhost", "root", "root", "vantil");
            self::$con->set_charset("utf8");
//            print self::$con->error;
//            print self::$con->character_set_name();
//            self::$con->query("SELECT @KEYWORD:='batata'");
            if (mysqli_connect_errno()) {
                printf("Connect failed: %s\n", mysqli_connect_error());
                exit();
            }
        }
        return self::$con;
    }
    
    public static function close_mysqli(){
        if (isset (self::$con)){
            self::$con->close();
        }
        return self::$con;
    }
    
    public static function startTransaction(){
        self::get_mysqli()->autocommit(FALSE);
    }
    
    public static function rollback(){
        self::get_mysqli()->rollback();
        self::get_mysqli()->autocommit(TRUE);
    }
    
    public static function commit(){
        self::get_mysqli()->commit();
        self::get_mysqli()->autocommit(TRUE);
    }
    
}
?>
